package com.mali.malibackenduser;


import com.mali.backendcommon.config.WebMvcConfiguration;
import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.mali.backendcommon.rpc.UserService;
import com.mali.malibackenduser.service.impl.UserServiceImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

@SpringBootApplication
@MapperScan(basePackages = "com.mali.malibackenduser.mapper")
@ComponentScan("com.mali")
@Import(WebMvcConfiguration.class)
public class MaliBackendUserApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(MaliBackendUserApplication.class, args);

    }

    @Bean
    public UserService userService() {
        return new UserServiceImpl();
    }
    @Override
    public void run(String... args) throws Exception {
        // 设置服务器配置
        ServerConfig serverConfig = new ServerConfig()
                .setProtocol("bolt") // 设置协议
                .setPort(12200)       // 设置端口
                .setDaemon(false);

        // 发布服务
        ProviderConfig< UserService> providerConfig = new ProviderConfig< UserService>()
                .setInterfaceId( UserService.class.getName()) // 设置接口
                .setRef(userService())                        // 设置实现
                .setServer(serverConfig)
                .setUniqueId("1.0");                           // 设置版本号

        providerConfig.export(); // 发布服务
    }
}


